package ils.services;

import ils.domain.catalog.model.Book;
import ils.domain.catalog.model.BookRepository;
import ils.domain.catalog.model.Category;
import ils.domain.catalog.model.CategoryRepository;
import ils.domain.issue.model.ShelfRepository;
import ils.domain.model.Branch;
import ils.domain.model.BranchRepository;
import ils.domain.issue.model.Item;
import ils.domain.issue.model.ItemRepository;
import ils.domain.issue.model.Shelf;
import ils.domain.model.User;
import ils.domain.model.UserRepository;

import ils.util.HibernateSession;
import ils.util.HibernateSessionManager;


public class AdminServiceImpl implements AdminService
{
    private UserRepository userRepository;
    private BranchRepository branchRepository;
    private HibernateSessionManager hibernateSessionManager;
    
    @Override
    public User addUser(User user)
    {
        try(HibernateSession session = hibernateSessionManager.getSession()){
            return userRepository.createUser(user);
        }
    }
    public void setUserRepository(UserRepository userRepository)
    {
        this.userRepository = userRepository;
    }
    public void setBranchRepository(BranchRepository branchRepository)
    {
        this.branchRepository = branchRepository;
    }

    public void setHibernateSessionManager(HibernateSessionManager hibernateSessionManager)
    {
        this.hibernateSessionManager = hibernateSessionManager;
    }

    @Override
    public User login(String email, String password)
    {
        try(HibernateSession hibernateSession = hibernateSessionManager.getSession() )
        {
            return userRepository.login(email, password);
        }
    }

    @Override
    public Branch addBranch(Branch branch) {
        try(HibernateSession session = hibernateSessionManager.getSession())
        {
            return branchRepository.createBranch(branch);
        }
    }
}
